<?php Yii::app()->clientScript->registerScript('info', "
    var jobid='$model->jobid';

    ", CClientScript::POS_HEAD); ?>
<?php //Yii::app()->clientScript->registerScript('jobid',"var jobid='$model->jobid';",CClientScript::POS_HEAD)?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/jobsdocuments.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/jobupdate.js', CClientScript::POS_BEGIN); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/salesPortal/poIndex.js', CClientScript::POS_BEGIN); ?>

<div id="left-col">
    <?php
    $this->renderPartial('_side', array(
        'location' => $model->location,
        'customer' => $model->location->customer,
        'job' => $model,
        'action' => 'update'
    ));
    ?>    
</div>

<div id="right-col">

    <div class="wrap">
        <div class="container">


            <div id="breadcrumb" style="display:none;"><span style="padding-left:10px;font-size:10px;color:#777777;" id="alsoviewing"></span></div>
            <div class="inside">

<?php
$this->renderPartial('_view', array(
    'model' => $model,
));
?>
                <div id="panel"></div>
                <ul id="tab" class="tabs tabs-with-summary">
                    <li class="active"><a id="tabNoteLink" href="#tabNote">Notes</a></li>
                    <li><a href="#tabBilling" >Billing</a></li>
                    <li><a href="#tabPo" >PO's</a></li>
                    <li class=""><a id="tabDocumentLink" href="#tabDocument">Documents</a></li>

                </ul>
                <div id="tab1"></div>
                <div id="tabPo">
                    <br/>
                    <a href="index.php?r=vendors/po/create&jobid=<?=$model->jobid?>" class="add-button">Add Purchase Order</a>
                    <br/>
                    <div id="customer-list"></div>
                </div>
                <div id="tabNote">
                    <br/>
                    <a href="javascript:void(0)" class="add-button" id="createNote">Add Note</a>

                    <div id="notes-list" class="">

                    </div>
                </div>
                <div id='tabBilling'>
                    <br/>
                    <a href='index.php?r=invoices/createQuote&jobnumber=<?= $model->jobid ?>' class='add-button' id='createQuote'>Add Quote</a>
                    <table width="500">
                        <thead>
                        <th></th>
                        <td>Reference</td>
                        <th>Number</th>
                        <th>Status</th>
                        <th>Amount</th>
                        </thead>
                        <tbody>
                            <?php
                            //display quote 
                            //$quoteList = $model->getQuoteList();
                            $quoteList = $model->quoteList;
                            $countQuote = count($quoteList);
                            if ($countQuote > 0) {
                                for ($i = 0; $i < $countQuote; $i++) {
                                    $item = $quoteList[$i];
                                    $style = '';
                                    if ($i == $countQuote - 1)
                                        $style = 'border-bottom:1px solid black;';
                                    echo "<tr style='$style'>";
                                    if ($i == 0)
                                        echo "<td>Quote</td>";
                                    else
                                        echo "<td></td>";
                                    echo "<td></td>";
                                    echo "<td><a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a></td>";
                                    echo "<td>" . $item->getQuoteStatusText() . "</td>";
                                    echo "<td>" . number_format($item->getTotal(),2) . "</td>";
                                    echo "<tr/>";
                                }
                            }else {
                                echo "<tr><td colspan=4>No quote have been created with this job number.</td></tr>";
                            }
                            ?>

                            <?php
                            //display sales orders
                            //$list = $model->getSalesOrdersList();
                            $list = $model->salesOrderList;
                            $countQuote = count($list);
                            if ($countQuote > 0) {
                                for ($i = 0; $i < $countQuote; $i++) {

                                    $item = $list[$i];
                                    $style='';
                                    if ($i == $countQuote - 1)
                                        $style = 'border-bottom:1px solid black;';
                                    echo "<tr style='$style'>";

                                    if ($i == 0)
                                        echo "<td>Sales Orders</td>";
                                    else
                                        echo "<td></td>";
                                    echo "<td>$item->quoteorg</td>";
                                    echo "<td><a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a></td>";
                                    echo "<td>" . $item->getQuoteStatusText() . "</td>";
                                    echo "<td>" . number_format($item->getTotal(),2) . "</td>";
                                    echo "<tr/>";
                                }
                            }else {
                                echo "<tr><td colspan=4>No sales orders have been created with this job number.</td></tr>";
                            }
                            ?>
                            <?php 
                            //display invoice
                            //$list = $model->getInvoiceList();
                            $list = $model->invoiceAndCMList;
                            $countQuote = count($list);
                            if ($countQuote > 0) {
                                for ($i = 0; $i < $countQuote; $i++) {

                                    $item = $list[$i];
                                    echo "<tr>";

                                    if ($i == 0)
                                        echo "<td>Invoice</td>";
                                    else
                                        echo "<td></td>";
                                    echo "<td>$item->salesordersorg</td>";
                                    echo "<td><a href='index.php?r=invoices/update&invoice=$item->invoice'>$item->invoice</a></td>";
                                    echo "<td>" . $item->getQuoteStatusText() . "</td>";
                                    echo "<td>" . number_format($item->getTotal(),2) . "</td>";
                                    echo "<tr/>";
                                }
                            }else {
                                echo "<tr><td colspan=4>No invoices have been created with this job number.</td></tr>";
                            }
                            ?>
                        </tbody>	

                    </table>
                </div>
                <div id="tabDocument">
                    <br/>
                    <iframe id="downloadFrame" src="" style="display:none;"></iframe>
                    <a class="add-button" href='javascript:void(0)' id="createJobDocument">Add Document</a>
                    <div id="document-list">

                    </div>
                </div>


            </div><!-- inside -->
        </div><!-- container -->
    </div><!-- wrap -->
<?php $this->renderPartial('application.views.copyright'); ?>
</div> <!-- left-col -->